﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
</head>
<body class="easyui-layout">
   
    <link href="../hcjsui/jquery-easyui-1.3.3/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../hcjsui/jquery-easyui-1.3.3/themes/icon.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" rev="stylesheet" type="text/css" href="../hcjsui/Styles/usbocx.css" />
    <style type="text/css">
        body
        {
            margin-left: 0px;
            margin-top: 0px;
            margin-right: 0px;
            margin-bottom: 0px;
            background-color: #EEF2FB;
        }

        .gridRow
        {
            width: 500px;
        }
    </style>
    <script src="../hcjsui/Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="../hcjsui/jquery-easyui-1.3.3/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../hcjsui/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js" charset="utf-8" type="text/javascript"></script>
    <script src="../hcjsui/Scripts/jquery.form.js" type="text/javascript"></script>
    <script src="../hcjsui/js/json2.js" type="text/javascript"></script>
    <script src="../hcjsui/js/_Define.js" type="text/javascript"></script>
    <script src="../hcjsui/js/customer.js" type="text/javascript"></script>
    <script type="text/javascript" src="../hcjsui/js/usbocx.js"></script>
    <script src="../hcjsui/Scripts/jquery.validate.js" type="text/javascript"></script>
    <script src="../hcjsui/js/easyui-extend/form.js" type="text/javascript"></script>
    <script src="../hcjsui/js/easyui-extend/window.js" type="text/javascript"></script>
    <script src="../hcjsui/js/validateExtends.js" type="text/javascript"></script>
    <script type="text/javascript" src="../js/hc.js"></script>
    <div id="ui_department_layout" class="easyui-layout" data-options="fit:true,border:false">
        <div region="north" title="角色管理" split="false" border="false" style="height: 60px;">
            <table width="98%">
                <tr>
                    <td class="auto-style1">
                        <form id="searchForm" method="post" runat="server">
                            <div>
                                名称：<input id="findRoleName" name="findRoleName" />
                                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="javascript:Search();">查询</a>&nbsp;&nbsp;<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="javascript:Reset();">重置</a>
                            </div>
                        </form>
                    </td>

                </tr>
            </table>
        </div>
        <div region="center" title="角色列表(可右键菜单)" style="padding: 0px;" border="false">

            <table id="grid1"></table>

        </div>
        <div data-options="region:'east',split:true,border:true,collapsed:true" title="部门成员"
            style="width: 580px;">
            <table id="ui_department_user_dg" data-options="fit:true,border:false">
            </table>
        </div>
    </div>
    <div id="itemEditContainer" class="easyui-window" title="信息管理" data-options="iconCls:'icon-save',closed:'true'" style="width: 550px; height: 400px">
        <div>
            <div class="edititemblock" style="padding: 5px 5px 5px 5px; font-size: 15px;">
                <form id="itemEdit" name="itemEdit" method="post" action="../ashx/sp.ashx">
                    <input type="hidden" class="actionValue" id="editAction" name="action" value="" />
                    <input type="hidden" id="id" name="id" />
                    <input type="hidden" id="tablename" name="tablename" value="" />
                    <input type="hidden" id="tablemidname" name="tablemidname" value="" />
                    <table cellpadding="5px" class="tableForm" width="100%">
                        <tr>
                            <td>名称：</td>
                            <td>

                                <input type='text' id='fRoleName' name='fRoleName' />
                            </td>

                        </tr>
                        <tr>

                            <td>说明：</td>
                            <td>
                                <input type='text' id='fDescription' name='fDescription' /></td>
                        </tr>


                        <tr>
                            <td>状态：</td>
                            <td>
                                <select id="fDelFlag" name="fDelFlag" style="width: 150px;">
                                    <option value="0" selected="selected">启用</option>
                                    <option value="1">禁用</option>
                                </select>
                            </td>

                        </tr>

                        <tr>
                            <td colspan="2" align="center"><a class="easyui-linkbutton btn-save" data-options="iconCls:'icon-ok'" href="javascript:void(0)" onclick="javascript:toolSubmit();">保存</a>
                                <a class="easyui-linkbutton btn-cancel" data-options="iconCls:'icon-cancel'" href="javascript:void(0)" onclick="javascript:$('#itemEdit')[0].reset();">重置</a></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
    </div>
    <div id="menu" class="easyui-menu" style="width: 50px; display: none;">
        <div data-options="iconCls:'icon-add'" onclick="toolAdd()">新增</div>
        <div data-options="iconCls:'icon-save'" onclick="toolUpdate()">修改</div>
        <div data-options="iconCls:'icon-delete'" onclick="toolDelete()">删除</div>
    </div>
    <script type="text/javascript">
        spsetBase("sysRolesDic", "RoleID", "sysRolesDic as T", "*", "#grid1", "mrrole", "角色");
        $(function () {
            //初始化列表
            BindGrid();
        });
        var oldSelectDepartmentId;   //上次点选
        function BindGrid() {
            $(grid1ID).datagrid({
                pagination: true, //是否显示分页控件
                fitColumns: true, //是否自适应宽度
                fit: true, //是否自适应父容器的大小
                loadMsg: "努力加载中...", //加载数据时，显示的提示信息
                rownumbers: true, //是否显示行号
                singleSelect: true, //是否单选
                remoteSort: false, //是否启用服务器排序
                //sortName: "id", //排序字段
                sortOrder: "ASC", //排序类型
                striped: true, //行显示交替背景
                idField: pTableIdName,
                pageSize: 20,
                pageList: [10, 20, 30, 40, 50],
                toolbar: ptoolbar.length == 0 ? null : ptoolbar,
                columns: [[
                   { field: "RoleID", title: "ID", width: 80, sortable: true, checkbox: true },
                   { field: "RoleName", title: "名称", width: 100, sortable: true },
                   { field: "Description", title: "说明", width: 80, sortable: true },
                   {
                       field: 'DelFlag', title: '状态', sortable: true, width: 60, align: 'center',
                       formatter: function (value, row, index) {
                           return value == "False" ? '启用' : '禁用';
                       }
                   }
                ]],

                onLoadSuccess: function (data) {
                    switch (data.message) {
                        case JsonResult.SessionOut:
                            $.messager.alert('系统出错', ' 登录超时，请重新登录!');
                            break;
                        case JsonResult.Error:
                            $.messager.alert('系统出错', data.data);
                            break;
                    }
                },
                onBeforeLoad: function (param) {
                    if (!$(this).datagrid('options').url) {
                        $(this).datagrid('options').url = spselUrl();
                    }
                    $.extend(param, $("#searchForm").formToJson());
                },
                onRowContextMenu: function (e, rowIndex, rowData) { //右键时触发事件
                    //三个参数：e里面的内容很多，真心不明白，rowIndex就是当前点击时所在行的索引，rowData当前行的数据
                    e.preventDefault(); //阻止浏览器捕获右键事件
                    $(this).datagrid("clearSelections"); //取消所有选中项
                    $(this).datagrid("selectRow", rowIndex); //根据索引选中该行
                    $('#menu').menu('show', {
                        //显示右键菜单
                        left: e.pageX,//在鼠标点击处显示菜单
                        top: e.pageY
                    });
                },
                onClickRow: function (index, row) {


                    if (oldSelectDepartmentId == row.RoleID) {  //点选的是相同的部门就不再请求数据
                        return;
                    }
                    oldSelectDepartmentId = row.RoleID;   //赋值
                    var $ui_department_layout = $("#ui_department_layout");
                    var eastDepartmentUser = $ui_department_layout.layout("panel", "east");

                    if (eastDepartmentUser.panel("options").collapsed) {   //判断是否展开
                        $ui_department_layout.layout("expand", "east");
                    }
                    eastDepartmentUser.panel("setTitle", "角色：" + row.RoleName + "-成员");

                    if ($("#ui_department_user_dg").data("datagrid")) {
                        $("#ui_department_user_dg").datagrid({       //请求数据
                            url: sposelUrl("View_RoleUserInfo as T ", "PKID,BranchName,DepName,LoginID,EmpName", "and RoleID=" + row.RoleID)//pageUrl + "?action=sel&tableinfo=mrBaseInf as T &refields=*&wheresp= and DepID=" + row.id,
                        });
                    }
                    else {
                        $("#ui_department_user_dg").datagrid({       //初始化datagrid
                            url: sposelUrl("View_RoleUserInfo as T ", "PKID,BranchName,DepName,LoginID,EmpName", "and RoleID=" + row.RoleID),
                            striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: true,
                            idField: 'PKID',
                            pageList: [20, 40, 60, 80, 100],
                            toolbar:
                            [{ id: 'btnAdd', text: '增加角色成员', iconCls: 'icon-add', handler: addRoleUser }],
                            columns: [[
                                 { field: 'PKID', title: 'ID', sortable: true, width: 80 },
                                 { field: 'BranchName', title: '机构', sortable: true, width: 80 },
                                 { field: 'DepName', title: '部门', sortable: true, width: 80 },
                                 { field: 'LoginID', title: '登录名', sortable: true, width: 80 },
                                 { field: 'EmpName', title: '姓名', sortable: true, width: 80 },

                   {
                       field: "y", title: "操作", width: 50, align: "center", formatter: function (value, row, index) {
                           return "<a href='#' style='color: #369591;' onclick='javascript:delroleuser(" + row.PKID + ")'>删除</a>";
                       }
                   }

                            ]]
                        });
                    }
                }
            });
        }
        function delroleuser(id) {
            hcdodel("sysEmpRoles", "PKID", id, function (s) {
                if (s == "ok")
                    $("#ui_department_user_dg").datagrid({
                        url: sposelUrl("View_RoleUserInfo as T ", "PKID,BranchName,DepName,LoginID,EmpName", "and RoleID=" + oldSelectDepartmentId)
                    });
            }
            );

        }
        function Search() {
            $(grid1).datagrid("load");
        }
        function Reset() {
            $("#findRoleName").val("");
        }
        function addRoleUser() {
            if (oldSelectDepartmentId == null)
            { $.messager.alert('提示', "请选选择角色"); return; }
            else
                showWindowlist("添加角色成员", "", "", "", "");
        }
        function showWindowlist(divname, tableinfo, refields, whereinfo, inputid) {
            $.showWindow({
                title: divname,
                height: 400,
                width: 800,
                winId: "hcshowtablesel",
                url: "mrseldepuser.html?showtype=0&tableinfo=" + tableinfo + "&refields=" + refields + "&whereinfo=" + whereinfo,
                onClose: function (closeData) {
                    if (closeData.data != null) {
                        $.ajax({
                            type: "get",
                            url: spPageUrl,
                            data: {
                                "action": "doProc",
                                "procName": "doProcSaveRoleUser",
                                "hcproleid": oldSelectDepartmentId,
                                "hcpuservalue": closeData.data

                            },
                            timeout: 3000,
                            async: false,
                            cache: false,
                            error: function () {
                                alert("error");
                            },
                            success: function (data) {
                                var result = JSON.parse(data);
                                switch (result.message) {
                                    case JsonResult.Success:
                                        $.messager.show({
                                            title: '提示信息',
                                            msg: result.data,
                                            showType: 'show'
                                        });
                                        $("#ui_department_user_dg").datagrid({       //请求数据
                                            url: sposelUrl("View_RoleUserInfo as T ", "PKID,BranchName,DepName,LoginID,EmpName", "and RoleID=" + oldSelectDepartmentId)
                                        });
                                        break;
                                    case JsonResult.Error:
                                        alert(result.data);
                                        break;
                                    default:
                                        break;
                                }

                            }
                        });
                    }
                }
            });
        }
    </script>
</body>
</html>
